//
//  ActivityDetailViewController.m
//  Socrates
//
//  Created by shy on 15/4/7.
//  Copyright (c) 2015年 shy. All rights reserved.
//

#import "ActivityDetailViewController.h"

#import "CircleImage.h"
#import "ImageGallery.h"
#import "RDVTabBarController.h"
#import "UserInfoViewController.h"

typedef enum {
    kActivity_time_item = 0,
    kActivity_location_item,
    kActivity_fee_item,
    kActivity_activity_hint_item,
    kActivity_Num,
} ActivityItems;

typedef enum {
    kActivity_information_section = 0,
    kActivity_comment_section,
    kActivity_Section_Nums,
} ActivitySections;

typedef enum {
    kActivity_information_section_row_num = 0,
    kActivity_comment_section_row_num,
    kActivity_Section_row_Nums,
} ActivitySectionRowNums;

static const int kLimitationRowHeight = 40.;

@implementation ActivityDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configGallaryView];
    [self configOwnerView];
    self.navigationItem.title = @"活动详情";
    self.tableView.scrollEnabled = NO;
}

- (void)configGallaryView {
    NSArray *images = [NSArray arrayWithObjects:[UIImage imageNamed:@"prefer_test_shop"],[UIImage imageNamed:@"user_info_bg"],[UIImage imageNamed:@"home_test_activity"], nil];
    ImageGallery *imageGallery = [[ImageGallery alloc] initWithImages:images];
    [self.gallaryView addSubview:imageGallery];
}

- (void)configOwnerView {
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGSize ownerSize = CGSizeMake([UIScreen mainScreen] .bounds.size.width, self.ownerView.frame.size.height);
    CGSize userSize = CGSizeMake(60, 60);
    CGFloat topEdge = 10.;
    CGFloat separateEdge = 6;
    CGFloat labelHeight = 15;
    CGFloat labelAEdge = userSize.width + 15 + 5;
    CGFloat labelBEdge = labelAEdge + 0.23*width + 15;
    self.user = [[UIButton alloc] initWithFrame:CGRectMake(15, (ownerSize.height - userSize.height)/2, userSize.width, userSize.height)];
    UIImage *userImage = [CircleImage circleImageWithName:@"angela_test" borderWidth:0 borderColor:[UIColor clearColor]];
    [self.user setImage:userImage forState:UIControlStateNormal];
    [self.user addTarget:self action:@selector(clickUser:) forControlEvents:UIControlEventTouchUpInside];
    [self.ownerView addSubview:self.user];
    
    self.userName = [[UILabel alloc] initWithFrame:CGRectMake(labelAEdge, topEdge, 0.23*width, labelHeight)];
//    self.userName.backgroundColor = [UIColor purpleColor];
    self.userName.textColor = [UIColor grayColor];
    self.userName.font = [UIFont systemFontOfSize:13.];
    self.userName.text = @"AngelaBaby";
    [self.ownerView addSubview:self.userName];
    
    self.userAge = [[UILabel alloc] initWithFrame:CGRectMake(labelAEdge, topEdge + labelHeight + separateEdge, 0.23*width, labelHeight)];
//    self.userAge.backgroundColor = [UIColor purpleColor];
    self.userAge.textColor = [UIColor grayColor];
    self.userAge.font = [UIFont systemFontOfSize:13.];
    self.userAge.text = @"21";
    [self.ownerView addSubview:self.userAge];
    
    self.userSchool = [[UILabel alloc] initWithFrame:CGRectMake(labelAEdge, topEdge + labelHeight*2 + separateEdge*2, 0.23*width, labelHeight)];
//    self.userSchool.backgroundColor = [UIColor purpleColor];
    self.userSchool.textColor = [UIColor grayColor];
    self.userSchool.font = [UIFont systemFontOfSize:13.];
    self.userSchool.text = @"对外经贸";
    [self.ownerView addSubview:self.userSchool];
    
    UIView *separeteLine = [[UIView alloc] initWithFrame:CGRectMake(labelAEdge + 0.23*width + 3, topEdge, 1., ownerSize.height - 2*topEdge)];
    separeteLine.backgroundColor = [UIColor colorWithRed:224/255. green:224/255. blue:224/255. alpha:1.];
    [self.ownerView addSubview:separeteLine];
    
    UILabel *hint = [[UILabel alloc] initWithFrame:CGRectMake(labelBEdge, topEdge, 0.35*width, labelHeight)];
//    hint.backgroundColor = [UIColor purpleColor];
    hint.textColor = [UIColor grayColor];
    hint.font = [UIFont systemFontOfSize:13.];
    hint.text = @"已经报名的伙伴们";
    [self.ownerView addSubview:hint];
    
    UIImageView *male = [[UIImageView alloc] initWithFrame:CGRectMake(labelBEdge, topEdge + labelHeight + separateEdge + 2, 12, 12)];
    male.image = [UIImage imageNamed:@"male"];
    [self.ownerView addSubview:male];
    
    self.maleNum = [[UILabel alloc] initWithFrame:CGRectMake(labelBEdge + 15, topEdge + labelHeight + separateEdge, 50, labelHeight)];
//    self.maleNum.backgroundColor = [UIColor purpleColor];
    self.maleNum.textColor = [UIColor grayColor];
    self.maleNum.font = [UIFont systemFontOfSize:13.];
    self.maleNum.text = @"6/6";
    [self.ownerView addSubview:self.maleNum];
    
    UIImageView *female = [[UIImageView alloc] initWithFrame:CGRectMake(labelBEdge, topEdge + labelHeight*2 + separateEdge*2 + 2, 12, 12)];
    female.image = [UIImage imageNamed:@"female"];
    [self.ownerView addSubview:female];
    
    self.femaleNum = [[UILabel alloc] initWithFrame:CGRectMake(labelBEdge + 15, topEdge + labelHeight*2 + separateEdge*2, 50, labelHeight)];
//    self.femaleNum.backgroundColor = [UIColor purpleColor];
    self.femaleNum.textColor = [UIColor grayColor];
    self.femaleNum.font = [UIFont systemFontOfSize:13.];
    self.femaleNum.text = @"2/6";
    [self.ownerView addSubview:self.femaleNum];
    
    UIImageView *heart = [[UIImageView alloc] initWithFrame:CGRectMake(width - 50, 20, 25, 20)];
    heart.image = [UIImage imageNamed:@"home_like"];
    [self.ownerView addSubview:heart];
    
    self.likes = [[UILabel alloc] initWithFrame:CGRectMake(width - 50, 40, 30, labelHeight)];
//    self.likes.backgroundColor = [UIColor purpleColor];
    self.likes.textColor = [UIColor grayColor];
    self.likes.font = [UIFont systemFontOfSize:13.];
    self.likes.text = @"23";
    self.likes.textAlignment = NSTextAlignmentCenter;
    [self.ownerView addSubview:self.likes];
    
}

- (void)clickUser: (id)sender {
    UserInfoViewController *vc = [[UserInfoViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    switch (section) {
        case kActivity_information_section:
            return 40;
            break;
        case kActivity_comment_section:
            return 30;
            break;
        default:
            break;
    }
    return 0;
}

- (UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *viewA = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 20)];
    viewA.backgroundColor = [UIColor colorWithRed:239/255. green:239/255. blue:244/255. alpha:1.];
    UILabel *hintA = [[UILabel alloc] initWithFrame:CGRectMake(23, 0, [UIScreen mainScreen].bounds.size.width - 46, 40)];
    hintA.textColor = [UIColor blackColor];
    hintA.text = @"周杰伦2015演唱会随行小伙伴";
    hintA.font = [UIFont systemFontOfSize:16.];
    [viewA addSubview:hintA];
    UIView *viewB = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 30)];
    viewB.backgroundColor = [UIColor colorWithRed:239/255. green:239/255. blue:244/255. alpha:1.];
    UILabel *hintB = [[UILabel alloc] initWithFrame:CGRectMake(23, 0, [UIScreen mainScreen].bounds.size.width - 46, 30)];
    hintB.textColor = [UIColor grayColor];
    hintB.text = @"评论";
    hintB.font = [UIFont systemFontOfSize:14.];
    [viewB addSubview:hintB];
    switch (section) {
        case kActivity_information_section:
            return viewA;
        case kActivity_comment_section:
            return viewB;
            break;
        default:
            break;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if([indexPath row] == kActivity_activity_hint_item) {
        return 60;
    } else {
        return kLimitationRowHeight;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return kActivity_Section_Nums;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    switch (section) {
        case kActivity_information_section_row_num:
            return kActivity_Num;
            break;
        case kActivity_comment_section_row_num:
            return 2;
        default:
            break;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellIdentifier = @"HomeCellIdentifier";
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    UIImageView *time = [[UIImageView alloc] initWithFrame:CGRectMake(23, 10, 20, 20)];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 0, [UIScreen mainScreen].bounds.size.width - 80, 40)];
    label.textColor = [UIColor grayColor];
    label.textAlignment = NSTextAlignmentLeft;
    label.font = [UIFont systemFontOfSize:15.];
    switch ([indexPath section]) {
        case kActivity_information_section:
            switch ([indexPath row]) {
                case kActivity_time_item:
                    time.image = [UIImage imageNamed:@"home_time"];
                    [cell addSubview:time];
                    label.text = @"2015/11/28/19:00-2015/12/30/19:00";
                    [cell addSubview:label];
                    break;
                case kActivity_location_item:
                    time.image = [UIImage imageNamed:@"home_location"];
                    [cell addSubview:time];
                    label.text = @"鸟巢体育馆";
                    [cell addSubview:label];
                    break;
                case kActivity_fee_item:
                    time.image = [UIImage imageNamed:@"home_fee"];
                    [cell addSubview:time];
                    label.text = @"288元/人";
                    [cell addSubview:label];
                    break;
                case kActivity_activity_hint_item:
                    cell.textLabel.text = @"周杰伦演唱会，真情邀请杰迷朋友一起来祝福，地点：鸟巢，水立方集合，希望准时";
                    cell.textLabel.textColor = [UIColor grayColor];
                    cell.textLabel.font = [UIFont systemFontOfSize:15.];
                    break;
                default:
                    break;
            }
            break;
        case kActivity_comment_section:
            
            break;
        default:
            break;
    }
    return cell;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.scrollView setContentSize:CGSizeMake(320,700)];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
    
    [super viewWillDisappear:animated];
}

@end
